package com.credithc.signature.facade.client;

import com.alibaba.fastjson.JSONObject;
import com.credithc.signature.common.ro.facade.ReSignData;
import com.credithc.signature.facade.controller.SignatureController;
import com.credithc.signature.facade.ro.RequestData;
import com.credithc.signature.facade.ro.RestSignatureReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 描 述: 签章重发接口<br/>
 * 作 者: Jingbo Hu<br/>
 * 创 建：2019年08⽉22⽇<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@RestController
@RequestMapping("/api/signaturefacade/v1")
@Slf4j
public class ReSignatureClient {

    @Resource
    private SignatureController signatureController;


    @ResponseBody
    @PostMapping("reSignature")
    public String reSignature(@RequestHeader String encryptKey, @RequestBody @Valid ReSignData reSignData) throws Exception {
        log.info("重签请求数据：" + reSignData);
        RestSignatureReq req = new RestSignatureReq();
        BeanUtils.copyProperties(reSignData, req);
        req.setRequestData(JSONObject.parseObject(reSignData.getRequestData(), RequestData.class));

        return signatureController.signature(encryptKey, req);
    }
}
